///
///Author: YYF
///Date: 2020-12-19 12:34:03
///Description:
///

import 'dart:io';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lh_shop_flutter/config/app_style.dart';
import 'package:lh_shop_flutter/page/tab_page.dart';
import 'package:lh_shop_flutter/provider/tabbar_index_provider.dart';
import 'package:provider/provider.dart';
import 'package:sp_util/sp_util.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

import 'page/routers/routers.dart';

void main() {
  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
    ).copyWith(statusBarBrightness: Brightness.dark);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => TabbarSelectedIndexProvider()),
      ],
      child: MyApp(),
    ),
  );
  SpUtil.getInstance();
}

final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    //初始化配置Router
    final router = FluroRouter();
    AppRoutes.configureRotes(router);
    AppRoutes.router = router;

    return ScreenUtilInit(
        designSize: Size(750, 1624),
        allowFontScaling: false,
        child: MaterialApp(
          title: '商城',
          navigatorKey: navigatorKey,
          locale: Locale('zh', 'CH'),
          localizationsDelegates: [
            GlobalCupertinoLocalizations.delegate,
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
          ],
          supportedLocales: [
            const Locale('zh', 'CH'),
            // const Locale('en', 'US'),
          ],
          theme: ThemeData(
            scaffoldBackgroundColor: AppColors.pageBackColor,
            appBarTheme: AppBarTheme(
              color: Colors.white,
              elevation: 0,
            ),
          ),
          debugShowCheckedModeBanner: false,
          onGenerateRoute: AppRoutes.router.generator,
          home: TabPage(),
          builder: (context, widget) {
            return MediaQuery(
              //设置文字大小不随系统设置改变
              data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
              child: widget,
            );
          },
        ));
  }
}
